package org.wu.framework.authorization.platform.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.authorization.platform.application.SysRoleApplication;
import org.wu.framework.authorization.platform.application.command.SysRoleCommand;
import org.wu.framework.authorization.platform.infrastructure.entity.SysRoleDO;
import org.wu.framework.authorization.platform.domain.model.sys.role.SysRole;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyController;
import org.wu.framework.lazy.orm.web.plus.AbstractLazyCrudProvider;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.spring.EasyController;

import java.util.List;

/**
 * describe 角色
 *
 * @author Jia wei Wu
 * @date 2023/05/17 11:19 晚上
 * @see DefaultDDDLazyController
 **/
@Tag(name = "角色提供者")
@EasyController("/role")
public class SysRoleProvider extends AbstractLazyCrudProvider<SysRoleDO, SysRoleDO, Long> {

    @Autowired
    private SysRoleApplication sysRoleApplication;

    /**
     * describe 新增角色
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @PostMapping("/story")
    public Result<SysRole> story(@RequestBody SysRoleCommand sysRoleCommand) {
        return sysRoleApplication.save(sysRoleCommand);
    }


    /**
     * describe 更新角色
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/
    @PutMapping("/updateOne")
    public Result<SysRole> updateOne(@RequestBody SysRoleCommand sysRoleCommand) {
        return sysRoleApplication.update(sysRoleCommand);
    }

    /**
     * describe 查询单个角色
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @GetMapping("/findOne")
    public Result<SysRole> findOne(@ModelAttribute SysRoleCommand sysRoleCommand) {
        return sysRoleApplication.findOne(sysRoleCommand);
    }

    /**
     * describe 查询多个角色
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/

    @GetMapping("/findList")
    public Result<List<SysRole>> findList(@ModelAttribute SysRoleCommand sysRoleCommand) {
        return sysRoleApplication.findList(sysRoleCommand);
    }

    /**
     * describe 删除角色
     *
     * @param
     * @return
     * @exception/throws
     * @author Jia wei Wu
     * @date 2023/05/17 11:19 晚上
     **/
    @DeleteMapping("/delete")
    public Result<SysRole> delete(@ModelAttribute SysRoleCommand sysRoleCommand) {
        return sysRoleApplication.delete(sysRoleCommand);
    }
}